import util from '@/common/js/util.js'
import axios from 'axios'
const host = '.'

//页面路径相关
const index_page = '/index.html'
const login_page = '/login.html'

//用户登陆
const to_login_url = host + '/api/login'

const get_menu_list_url = host + '/api/menu/list'

//程序列表 这是入口，之后进入扫描记录，或者其他
const get_program_list_url = host + '/api/program/list'
//扫描记录相关
const get_scan_list_url = host + '/api/scan/record/list'
const get_export_scan_list_url = host + '/api/scan/record/excel'//导出文件
const get_scan_filter_url = host + '/api/scan/record/filter'//筛选条件
const delete_scan_list_url = host + '/api/scan/record/delete'
const cancel_high_light_scan_list_url = host + '/api/scan/record/cancelHighLight'

const get_speclib_List_url = host + '/api/speclib/list'
const get_bom_list_url = host + '/api/bom/list'
const get_client_list_url = host + '/api/client/list'

const get_surplus_list_url = host + '/api/component/surplus/get'

//电子看板
const get_line_status_url = host + '/api/board/produce_status'
const save_now_produce_url = host+'/api/now/produce/save'
const save_wait_produce_url = host+'/api/wait/produce/save'
const get_line_board_url = host+'/api/now/produce/list'
const update_producing_hours = host+'/api/producing/hours/update'

const default_page_num = 1
const default_page_size = 20

const get_counter_config_url = host + '/api/counter/config/list'
const update_couter_config = host +'/api/counter/config/update'
const rollback_counter = host +'/api/counter/config/rollbackCounter'

const delete_export_scan_list_url = host +'/api/scan/record/deletebyfilter'


const get_user_list_url = host + '/api/user/list'
const update_user_url = host + '/api/user/update'
const delete_user_url = host + '/api/user/delete'
const add_user_url = host + '/api/user/add'


const update_total_amount_url = host + '/api/component/surplus/updateTotalAmount'

const program_download_url = host + '/api/program/download'
const program_file_detail_url = host + '/api/program/file/detail'

const get_line_list_url = host + '/api/line/list'

//扫码枪相关接口
//新增扫描枪
const add_pcbaScanner =  host + '/api/pcbaScanner/add'
//设备类型
const get_machineType_list =  host + '/api/machineType/list'
const delete_pcbaScanner = host + '/api/pcbaScanner/delete'
//更新扫描枪
const update_pcbaScanner =  host + '/api/pcbaScanner/update'
//查询扫描枪
const get_pcbaScanner_list =  host + '/api/pcbaScanner/list'
const get_pcbaScanner_detail =  host + '/api/pcbaScanner/detail'


//pcba追溯相关接口
const post_pcba_record_list =  host + '/api/pcba/record/list'
const post_delete_pcba_record =  host + '/api/pcba/record/delete'
const post_pcba_record_export =  host + '/api/pcba/record/export'
const post_pcba_record_export_bom =  host + '/api/pcba/record/exportBom'
const post_pcba_record_aoi =  host + '/api/pcba/record/aoi'
const post_pcba_record_repair =  host + '/api/pcba/record/repair'
const get_scan_record_listHistory =  host + '/api/scan/record/listHistory' //扫描历史

const post_pcba_record_upload = host + '/api/pcba/record/upload'

// 获取回流焊温度记录
const get_reflow_temp_detail =  host + '/api/reflow/temp/detail'

// 获取spi结果详情
const get_spi_detail_by_PCBARecordId =  host + '/api/spi/detail/findByPCBARecordId'


//根据lineName查最新的炉温历史
const get_reflow_last_temp_by_lineName =  host + '/api/reflow/temp/findLastTempByLineName'


//增加 pcba 追溯 下方新增 pcba 统计菜单
const get_pcba_record_getStatistics =  host + '/api/pcba/record/getStatistics'

//spi完成率
const get_pcba_record_getNotStartRecords =  host + '/api/pcba/record/getNotStartRecords'

// 回流焊完成率
const get_pcba_record_getNotReflowRecords =  host + '/api/pcba/record/getNotReflowRecords'

// AOI完成率
const get_pcba_record_getNotAOIRecords =  host + '/api/pcba/record/getNotAOIRecords'

//钢网
const get_stencil_list =  host + '/api/stencil/list'

const requestStencilList=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(get_stencil_list, data, code200, error)
}

const post_stencil_update = host + '/api/stencil/update'
const requestUpdateStencil = function (data, code200, error) {
  util.myPost(post_stencil_update, data, code200, error)
}


//锡膏
const get_solderPaste_list =  host + '/api/solderPaste/list'
const requestSolderPasteList=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(get_solderPaste_list, data, code200, error)
}

const requestGetPcbaRecordGetNotAOIRecords=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(get_pcba_record_getNotAOIRecords, data, code200, error)
}


const requestGetPcbaRecordGetNotStartRecords=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(get_pcba_record_getNotStartRecords, data, code200, error)
}

const requestGetPcbaRecordGetNotReflowRecords=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(get_pcba_record_getNotReflowRecords, data, code200, error)
}

const requestGetPcbaRecordGetStatistics=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(get_pcba_record_getStatistics, data, code200, error)
}



const requestGetReflowLastTempByLineName=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(get_reflow_last_temp_by_lineName, data, code200, error)
}

//新增或者更新回流焊设计炉温
const post_reflow_temp_createOrUpdate = host + '/api/reflow/temp/design/createOrUpdate'
const requestCreateOrUpdateReflowTemp = function (data, code200, error) {
  util.myPost(post_reflow_temp_createOrUpdate, data, code200, error)
}

//列出所有回流焊设计炉温记录
const get_reflow_temp_list =  host + '/api/reflow/temp/design/list'
const requestGetReflowTempList=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(get_reflow_temp_list, data, code200, error)
}
//删除回流焊设计炉温记录
const delete_reflow_temp_design =  host + '/api/reflow/temp/design/delete'
const requestDeleteReflowTempDesign=function (params, code200, error) {
  let data = {
    params
  }
  util.myGet(delete_reflow_temp_design, data, code200, error)
}
//

const requestGetReflowTempDetail=function (params, code200, error) {
  let data = {
    params
  }

  util.myGet(get_reflow_temp_detail, data, code200, error)
}
const requestSpiDetailByPCBARecordId=function (params, code200, error) {
  let data = {
    params
  }

  util.myGet(get_spi_detail_by_PCBARecordId, data, code200, error)
}



const requestPcbaRecordUpload = function (data, code200, error) {
  util.myPost(post_pcba_record_upload, data, code200, error)
}

const requestPcbaRecordList = function (data, code200, error) {
  util.myPost(post_pcba_record_list, data, code200, error)
}
const requestDeletePcbaRecord = function (params, code200, error) {
  util.myPostParams(post_delete_pcba_record, params, code200, error)
}
const requestPcbaRecordExport = function (data, code200, error) {
  util.myPostExcel(post_pcba_record_export, data).then(res=>{
    code200(res)
  })
}
const requestPcbaRecordExportBom = function (data, code200, error) {
  util.myPost(post_pcba_record_export_bom, data, code200, error)
}
//上传AOI检测结果
const requestPcbaRecordAoi = function (data, code200, error) {
  util.myPostExcel(post_pcba_record_aoi, data).then(res=>{
    code200(res)
  })
}
//上传维修过站结果
const requestPcbaRecordRepair = function (data, code200, error) {
  util.myPostExcel(post_pcba_record_repair, data).then(res=>{
    code200(res)
  })
}
const requestScanRecordListHistory=function (params, code200, error) {
  util.myGet(get_scan_record_listHistory, {params}, code200, error)
}

// 新增扫码枪
const requestAddPcbaScanner=function (data, code200, error) {
  util.myPost(add_pcbaScanner, data, code200, error)
}

const requestGetMachineTypeList=function (params, code200, error) {
  util.myGet(get_machineType_list, {params}, code200, error)
}

const requestDeletePcbaScanner=function (params, code200, error) {
  util.myGet(delete_pcbaScanner, {params}, code200, error)
}
// 更新扫码枪
const requestUpdatePcbaScanner=function (data, code200, error) {
  util.myPost(update_pcbaScanner, data, code200, error)
}
// 扫码枪列表
const requestGetPcbaScannerList=function (params, code200, error) {
  util.myGet(get_pcbaScanner_list, {params}, code200, error)
}

const requestGetPcbaScannerDetail=function (params, code200, error) {
  util.myGet(get_pcbaScanner_detail, {params}, code200, error)
}

//修改站位余量的总量
const requestUpdateTotalAmount=function (data, code200, error) {
  util.myPost(update_total_amount_url, data, code200, error)
}


//用户请求登陆
const requestLogin = function (username, password, code200, error) {
  var data = {
    params: {
      username: username,
      password: password,
    }
  };
  // console.log('sssssssss')
  // console.log(Vue)
  // util.showErrorToast('ddddd')
  util.myGet(to_login_url, data, code200, error)
}

//产线的当前生产信息和待生产信息
const requestLineStatus = function (lineName,code200, error) {
  let data = {
    params: {
      lineName: lineName,
    }
  }

  util.myGet(get_line_status_url, data, code200, error)
}

const requestLineList = function (code200, error) {
  let data = {
    params: {
    }
  }

  util.myGet(get_line_list_url, data, code200, error)
}


//请求菜单列表
const requestMenuList = function (code200, error) {
  util.myGet(get_menu_list_url, {}, code200, error)
}

//请求程序列表
const requestProgramList = function (lineName, pageNum, pageSize, code200, error) {

  let data = {
    params: {
      lineName: lineName,
      page: pageNum,
      size: pageSize,
    }
  }

  util.myGet(get_program_list_url, data, code200, error)

}

const requestProgramDownload = function (path, code200, error) {

  let data = {
    params: {
      path
    }
  }

  util.myGet(program_download_url, data, code200, error)

}



//扫描记录
const requestScanList = function (lineName, programName, pageNum, pageSize, equipmentName, standPosition, startTime, endTime, code200, error) {

  let data = {
    params: {
      lineName: lineName,
      programName: programName,
      equipmentName: equipmentName,
      username: "",
      standPosition: standPosition,
      startTime: startTime,
      endTime: endTime,
      page: pageNum,
      size: pageSize,
    }
  }

  util.myGet(get_scan_list_url, data, code200, error)
}

//这个是筛选条件
const requestScanListFilter = function (lineName, code200, error) {

  let data = {
    params: {
      lineName: lineName,
    }
  }
  util.myGet(get_scan_filter_url, data, code200, error)

}

//余量列表
const requestSurplusList = function (lineName, programName, code200, error) {

  let data = {
    params: {
      lineName: lineName,
      programName: programName
    }
  }

  util.myGet(get_surplus_list_url, data, code200, error)
}

//导出扫描记录文件
const requestExportScanList = function (lineName, programName, equipmentName, standPosition, startTime, endTime, exportData, code200, error) {
  let data = {
    //筛选信息
    params: {
      lineName: lineName,
      programName: programName,
      equipmentName: equipmentName,
      username: "",
      standPosition: standPosition,
      startTime: startTime,
      endTime: endTime,

      //导出信息
      orderNo: exportData.orderNum,
      orderQuantity: exportData.orderCount,
      customerName: exportData.customName,
      productName: exportData.productName,
    }
  }

  util.myGet(get_export_scan_list_url, data, code200, error)

}

//删除扫描记录文件
const requestDeleteExportScanList = function (lineName, programName, equipmentName, standPosition, startTime, endTime, code200, error) {
  let data = {
    //筛选信息
    params: {
      lineName: lineName,
      programName: programName,
      equipmentName: equipmentName,
      username: "",
      standPosition: standPosition,
      startTime: startTime,
      endTime: endTime,

    }
  }

  util.myGet(delete_export_scan_list_url, data, code200, error)

}

//删除扫描记录
const requestDeleteScanList = function (ids, code200, error,lastdo) {
  var data = {
    params: {
      ids: ids.join()
    },//1,2,1,3
  };

  util.myGet(delete_scan_list_url, data, code200, error,lastdo)
}


const requestCancelHighLightScanList = function (ids, code200, error,lastdo) {
  var data = {
    params: {
      ids: ids.join()
    },//1,2,1,3
  };

  util.myGet(cancel_high_light_scan_list_url, data, code200, error,lastdo)
}

//获取bom列表，bom列表即最后一层
const requestBomList = function (lineName, code200, error) {
  var data = {
    params: {
      lineName: lineName
    },
  }

  util.myGet(get_bom_list_url, data, code200, error)
}

//获取客户列表
const requestClientList = function (pageNum, pageSize,code200,error) {
  var data = {
    params: {
      page: pageNum,
      size: pageSize,
    }
  }
  util.myGet(get_client_list_url, data, code200, error)
}

//获取规格库
const requestSpeclibList = function (clientid, pageNum, pageSize, code200, error) {
  var data = {
    params: {
      clientid: clientid,
      page: pageNum,
      size: pageSize,
    }
  }

  util.myGet(get_speclib_List_url, data, code200, error)

}



//保存当前生产信息
const requestSaveNowProduce = function (nowProduce, code200, error) {
  util.myPost(save_now_produce_url, nowProduce, code200, error)
}
const requestSaveWaitProduce = function (waitProduce, code200, error) {
  util.myPost(save_wait_produce_url, waitProduce, code200, error)
}

const requestUpdateProducingHours=function (data, code200, error) {
  util.myPost(update_producing_hours, data, code200, error)
}

//编辑 计数器配置 计数值
const requestUpdateCountNum=function (data, code200, error) {
  util.myPost(host+'/api/counter/config/updateCountNum', data, code200, error)
}



//获取客户列表
const requestLineBoard = function (code200,error) {
  var data = {
    params: {
      // page: pageNum,
      // size: pageSize,
    }
  }
  util.myGet(get_line_board_url, data, code200, error)
}


//获取计数器配置
const requestCouterConfig = function (code200,error) {
  var data = {
    params: {
      // page: pageNum,
      // size: pageSize,
    }
  }
  util.myGet(get_counter_config_url, data, code200, error)
}

const requestUpdateCouterConfig=function (data, code200, error) {
  util.myPost(update_couter_config, data, code200, error)
}

const requestRollbackCounter = function (mac,lineName,code200, error) {
  var data = {
    params: {
      mac,
      lineName,

    }
  }
  util.myGet(rollback_counter, data, code200, error)
}





const requestUserList = function (pageNum,pageSize,code200, error) {
  var data = {
    params: {
      page: pageNum,
      size: pageSize,
    }
  }
  util.myGet(get_user_list_url, data, code200, error)
}


const requestUpdateUserList = function (id,username,password,roles,code200, error) {
  var data = {
    params: {
      id,
      username,
      password,
      roles
    }
  }
  util.myGet(update_user_url, data, code200, error)
}


const requestDeleteUserList = function (id,code200, error) {
  var data = {
    params: {
      id
    }
  }
  util.myGet(delete_user_url, data, code200, error)
}


const requestAddUserList = function (username,password,roles,code200, error) {
  var data = {
    params: {
      username,
      password,
      roles
    }
  }
  util.myGet(add_user_url, data, code200, error)
}

const requestProgramDetail = function (id,code200, error) {
  var data = {
    params: {
      id
    }
  }
  util.myGet(program_file_detail_url, data, code200, error)
}


// const program_file_detail_url = host + '/api/program/file/detail'
const requestGetCompanyName = function (code200, error) {
  var data = {
    params: {
    }
  }
  util.myGet(host +'/api/sys/appName', data, code200, error)
}
//
// const  requestSaveCompanyName =function (data, code200, error) {
//   util.myPost(update_couter_config, data, code200, error)
// }


export default {
  requestUpdateTotalAmount,
  requestGetCompanyName,
  // requestSaveCompanyName,
  requestLogin,
  requestMenuList,
  requestProgramList,
  requestProgramDownload,
  requestScanList,
  requestScanListFilter,
  requestExportScanList,
  requestDeleteScanList,
  requestCancelHighLightScanList,
  requestBomList,
  requestClientList,
  requestSpeclibList,
  requestLineStatus,
  requestSaveNowProduce,
  requestSaveWaitProduce,
  requestLineBoard,
  requestUpdateProducingHours,
  requestUpdateCountNum,
  requestSurplusList,
  requestCouterConfig,
  requestUpdateCouterConfig,
  requestRollbackCounter,
  requestDeleteExportScanList,
  requestUserList,
  requestUpdateUserList,
  requestDeleteUserList,
  requestAddUserList,
  requestProgramDetail,
  requestGetPcbaScannerList,
  requestAddPcbaScanner,
  requestUpdatePcbaScanner,
  requestGetPcbaScannerDetail,
  requestDeletePcbaScanner,
  requestLineList,
  requestPcbaRecordList,
  requestDeletePcbaRecord,
  requestPcbaRecordExport,
  requestPcbaRecordExportBom,
  requestScanRecordListHistory,
  requestPcbaRecordAoi,
  requestPcbaRecordRepair,
  requestPcbaRecordUpload,
  requestGetMachineTypeList,
  requestSpiDetailByPCBARecordId,
  requestGetReflowTempDetail,

  requestGetReflowLastTempByLineName,
  requestCreateOrUpdateReflowTemp,
  requestGetReflowTempList,
  requestDeleteReflowTempDesign,
  requestGetPcbaRecordGetStatistics,
  requestGetPcbaRecordGetNotStartRecords,
  requestGetPcbaRecordGetNotAOIRecords,
  requestGetPcbaRecordGetNotReflowRecords,
  requestStencilList,
  requestUpdateStencil,
  requestSolderPasteList,
}










